import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';
import { useUserStore } from '@/store/modules/user';

// 获取全部仓库列表
export function getAllWarehouseList() {
    return request.get<AjaxResponse['warehouseList']>(HttpUrl.getAllWarehouseList);
}

// 获取仓库列表
export function getWarehouseList(warehouseName: string) {
    return request.get<AjaxResponse['warehouseList']>(HttpUrl.getWarehouseList, { params: { warehouseName } });
}

// 初始化仓库
export function initWarehouseList(warehouseData: { location: string; abscissa: string; ordinate: number }[]) {
    return request.post(HttpUrl.initWarehouseList, { warehouseData });
}

type UpdateProductWarehouseForm = {
    _id: string;
    name: string;
    number: number;
    ordinate: number;
    abscissa: string;
    productId: string;
};
// 更新仓库信息
export function updateWarehouseInfo(
    updateMode: 'update' | 'stack' | 'delete',
    updateProductWarehouseForm: UpdateProductWarehouseForm,
    creator: string = useUserStore().username,
    creatorId: string = useUserStore().id
) {
    return request.post(HttpUrl.updateWarehouseInfo, { updateMode, updateProductWarehouseForm, creator, creatorId });
}
